package com.tobeface.wechat.request;

import com.tobeface.modules.lang.Requires;

/**
 * @author loudyn
 */
public abstract class AbstractWeChatApiRequestBuilder implements WeChatApiRequestBuilder {

    protected static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 5000;
    protected static final int DEFAULT_WAIT_TIMEOUT_MILLIS = 5000;

    private final WeChatRequest request;

    /**
     * @param url
     * @param verb
     */
    public AbstractWeChatApiRequestBuilder(String url, WeChatRequest.Verb verb) {
        Requires.hasText(url);
        Requires.notNull(verb);
        this.request = WeChatRequest.of(url, verb);
    }

    @Override
    public final WeChatRequest build() {
        // default setting, can be modify on configRequest.
        request.waitTimeoutMillis(DEFAULT_WAIT_TIMEOUT_MILLIS);
        request.connectTimeoutMillis(DEFAULT_CONNECT_TIMEOUT_MILLIS);
        configRequest(request);
        return request;
    }

    /**
     * @param request
     */
    protected abstract void configRequest(WeChatRequest request);
}
